package com.qs.rocketmq.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qs.rocketmq.order.entity.Transaction;
import com.qs.rocketmq.order.mapper.TransactionMapper;
import com.qs.rocketmq.order.service.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TransactionServiceImpl implements TransactionService {

    @Autowired
    private TransactionMapper transactionMapper;

    @Override
    public boolean checkTransactionStatus(String transactionId) {
        QueryWrapper<Transaction> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("transaction_id", transactionId);
        return transactionMapper.selectCount(queryWrapper) > 0;
    }

    @Transactional
    @Override
    public void save(Transaction transaction) {
        transactionMapper.insert(transaction);
    }
}
